<?php
namespace App\Model\Examples;

use PhalApi\Model\NotORMModel as NotORM;

/**
 *文章管理
 */

class ArticleList extends NotORM {

    protected function getTableName($id) {
        return 'article_list';
    }

    public function getListItems($page, $perpage) {
//        return $this->getORM()
//            ->select('*')
//            //->where('state', $state)
//            ->order('updatetime DESC')
//            ->limit(($page - 1) * $perpage, $perpage)
//            ->fetchAll();
        $sql1 = 'SELECT article_type.*,article_list.*
                  FROM article_type,article_list WHERE article_list.typeid = article_type.id
                  order by updatetime desc limit :start,:size';
        $params = array(':start' => ($page - 1) * $perpage, ':size' => $perpage);
        return $this->getORM()->queryAll($sql1, $params);
    }
    //根据openid获得用户详情
    public function getArticleByTID($id) {
        $total = $this->getORM()
            ->where('typeid', $id);
        return $total;
    }
    public function getListTotal() {
        $total = $this->getORM()
            ->select('*')
            //->where('state', $state)
            ->count('id');

        return intval($total);
    }

}
